package 滑动窗口;

public class LeetCode713_乘积小于K的子数组 {
    public int numSubarrayProductLessThanK(int[] nums, int k) {
        if (k <= 1) return 0;
        int prod = 1, ans = 0, left = 0;
        for (int right = 0; right < nums.length; right++) {
            prod *= nums[right];
            while (prod >= k) prod /= nums[left++];
            // 固定右边区间，是为了保证不重复错乱
            ans += right - left + 1;
        }
        return ans;
    }
}
